<?php

namespace app\api\controller;

use app\common\controller\Api;
use EasyWeChat\Factory;
use app\api\controller\My;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }
    public function getPhonetype()
    {
        $ua = $this->request->request('ua');
        return $this->success('', my::getPhonetype($ua));
    }
    /**
     * 腾讯云市场回调
     */
    public function txyCallback()
    {
        //https://v5.sx2b2c.com/api/index/txyCallback
        $r = json_encode($this->request->request());
        my::dingding('腾讯云订单：' . $r);
        $input = $this->request->getInput();
        my::dingding('腾讯云订单2：' . $input);
        $echoback = $this->request->request('echoback');
        $eventId = $this->request->request('eventId');
        $timestamp = $this->request->request('timestamp');
        $arr = json_decode($input, true);
        //{"orderId":"5252252786585423","signId":"78678586876","openId":"52354353asdsfs4245254252345353543","accountId":"52353535353","appId":0,"productId":1,"resourceId":"","productInfo":null,"instanceExpireTime":"2023-11-19 20:20:20","extendInfo":null,"action":"renewInstance","extentBillingInfo":null,"requestId":""}
        //   return $timestamp;
        if ($arr['action'] == 'createInstance') { //新购
            $data = [
                'signId' => '555',
                'appInfo' => '555',

            ];
            return json_encode($data);
            //{"orderId":"2452365437858254235","openId":"52354353asdsfs4245254252345353543","accountId":"52353535353","productId":1,"appId":0,"resourceId":"","productInfo":{"productName":"fgsgf","isTrial":false,"spec":"","timeSpan":1,"timeUnit":"","ccsDetail":null,"cycleNum":1},"extendInfo":{"comment":"dddd"},"action":"createInstance","extentBillingInfo":null,"requestId":""}
        }
        if ($arr['action'] == 'renewInstance') { //续费
            $data = [
                'success' => true,
            ];
            return json_encode($data);
        }
        if ($arr['action'] == 'expireInstance') { //过期
            $data = [
                'success' => true,
            ];
            return json_encode($data);
        }
        if ($arr['action'] == 'destroyInstance') { //销毁
            $data = [
                'success' => true,
            ];
            return json_encode($data);
        }
        if ($arr['action'] == 'modifyInstance') { //变配
            $data = [
                'success' => true,
            ];
            return json_encode($data);
        }

        return json_encode(['echoback' => $timestamp, 'eventId' => $eventId, 'timestamp' => $timestamp]);
    }


    /**
     * 小程序手机号获取
     */
    public  function getPhoneNumber()
    {
        $code = $this->request->request('code');
        $rst =  Wechat::getPhoneNumber($code);
        return $this->success('', $rst);
    }
}
